/**
 * Created by Administrator on 2016/5/13.
 */
$(function () {
    var url=$('#add-url').val();
    var url_del=$('#del-url').val();
    var url_rec=$('#rec-url').val();
    var url_save=$('#save-url').val();
    var app={
        add:function(obj){
            var loading=layer.load(1);
            $.post(
                url,
                {u_name:$('#u_name').val(),u_email:$('#u_email').val(),u_pwd:$('#u_pwd').val(),u_repwd:$('#u_repwd').val(),u_sex:$('#u_sex').val(),u_type_id:$('#u_type_id').val(),u_tel:$('#u_tel').val()},
                function(res){
                    layer.close(loading);
                    if(res.status==1){
                        layer.msg(res.info,{icon:1});
                        window.location.reload();
                    }else{
                        layer.msg(res.info,{icon:2});
                        window.location.reload();
                    }
                });
        },

        delect:function(obj){
            var loading=layer.load(1);
            $.post(
                url_del,
                {u_id:obj.attr('data-id-del')},
                function(res){
                    layer.close(loading);
                    if(res.status==1){
                        layer.msg(res.info,{icon:1});
                        window.location.reload();
                    }else{
                        layer.msg(res.info,{icon:2});
                        window.location.reload();
                    }
                });
        },

        recover:function(obj){
            var loading=layer.load(1);
            $.post(
                url_rec,
                {u_id:obj.attr('data-id-rec')},
                function(res){
                    layer.close(loading);
                    if(res.status==1){
                        layer.msg(res.info,{icon:1});
                        window.location.reload();
                    }else{
                        layer.msg(res.info,{icon:2});
                        window.location.reload();
                    }
                });
        },

        save:function(obj){
            var loading=layer.load(1);
            $.post(
                url_save,
                {u_id:obj.attr('save-data'),u_type_id:$('#u_type_id').val()},
                function(res){
                    layer.close(loading);
                    if(res.status==1){
                        layer.msg(res.info,{icon:1});
                        window.location.reload();
                    }else{
                        layer.msg(res.info,{icon:2});
                        window.location.reload();
                    }
                });
        },

    }
    $('.add').click(function () {
        app.add($(this));
    });
    $('.del').click(function(){
       app.delect($(this));
    });
    $('.rec').click(function(){
        app.recover($(this));
    });
    $('.save').click(function(){
        app.save($(this));
    });

})

